package android.slc.cim.client.receiver;

import android.slc.cim.client.CIMPushCompatManager;
import android.slc.cim.client.constant.CIMCompatConstant;

import com.farsunset.cim.sdk.android.CIMEventBroadcastReceiver;
import com.farsunset.cim.sdk.android.constant.RequestKey;
import com.farsunset.cim.sdk.android.model.ReplyBody;

/**
 * @Description:
 * @Author: sunlunchang
 * @CreateDate: 2022/03/30 下午 2:55
 */
public abstract class CIMEventBroadcastCompatReceiver extends CIMEventBroadcastReceiver {

    @Override
    public void onReplyReceived(ReplyBody body) {
        handlerBindReply(body);
        super.onReplyReceived(body);
    }

    @Override
    public void onConnectFailed() {
        CIMPushCompatManager.setBind(false);
        super.onConnectFailed();
    }

    @Override
    public void onConnectionClosed() {
        CIMPushCompatManager.setBind(false);
        super.onConnectionClosed();
    }

    private void handlerBindReply(ReplyBody body) {
        if (RequestKey.CLIENT_BIND.equals(body.getKey()) && CIMCompatConstant.Status.REPLY_CODE_SUCCEED.equals(body.getCode())) {
            onBindSucceed();
        }
    }

    /**
     * 绑定账号成功
     */
    public void onBindSucceed() {
        //绑定成功
        CIMPushCompatManager.setBind(true);
    }
}
